package com.zhaolang.qogir.ui.manage;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.zhaolang.qogir.R;
import com.zhaolang.qogir.domain.BaseCall;
import com.zhaolang.qogir.domain.BaseResp;
import com.zhaolang.qogir.domain.ReqFactory;
import com.zhaolang.qogir.domain.WaresManage;
import com.zhaolang.qogir.ui.BaseActivity;
import com.zhaolang.qogir.ui.TitleView;
import com.zhaolang.qogir.util.Slog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ActivityManageProductAddClassify extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.vg_title)
    RelativeLayout vgTitle;
    @BindView(R.id.manage_product_class)
    EditText manageProductClass;
    @BindView(R.id.manage_product_description)
    EditText manageProductDescription;
    @BindView(R.id.manage_product_save)
    Button manageProductSave;
    private TitleView mTitle;
    private WaresManage waresManage;

    private BaseCall<BaseResp> updateShopProductClassAsync = new BaseCall<BaseResp>() {
        @Override
        public void call(BaseResp resp) {
            // TODO Auto-generated method stub
            if (resp.isRequestSuccess()) {
                finish();
            } else {
                Slog.e("Failed update mProductClassCallback!!!!!!!  " + resp.getMessage());
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage_product_classify);
        ButterKnife.bind(this);
        waresManage = ReqFactory.buildInterface(this,
                WaresManage.class);

        initView();
    }

    private void initView() {
        View title = findViewById(R.id.vg_title);
        mTitle = new TitleView(this, title);
        mTitle.setCenterText(R.string.ui_manage_string_classify_add, null);
        mTitle.setLeftIcon(R.drawable.btn_back, this);
        mTitle.setRightText(R.string.ui_manage_string_save, null);
        mTitle.setRightText(R.string.ui_manage_string_save, this);
    }

    /**
     * handler save button event
     */
    private void handleSaveProcess() {
        if (TextUtils.isEmpty(manageProductClass.getText()) || TextUtils.isEmpty(manageProductDescription.getText())) {
            Toast.makeText(this, "请输入分类名或者描述", Toast.LENGTH_SHORT).show();
            return;
        }
        WaresManage.ProductClassBeanReq bean = new WaresManage.ProductClassBeanReq();
        bean.setProclassName(manageProductClass.getText().toString());
        waresManage.updateShopProductClassAsync(bean, updateShopProductClassAsync);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case TitleView.ID_LEFT:
                finish();
                break;
            case TitleView.ID_RIGHT:
                break;
            default:
                break;
        }
    }

    @OnClick(R.id.manage_product_save)
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.manage_product_save:
                handleSaveProcess();
                break;
            default:
                break;
        }
    }
}
